<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.2.1/axios.js"></script>
</head>

<body>
    <button>获取数据</button>
    <button>获取学员</button>
    <script>
        // 获取ul和按钮
        let btns = document.querySelectorAll('button');

        //1. 请求拦截器 - 拦截的是配置对象 config
        axios.interceptors.request.use((config)=>{
            // ... 操作config对象
            config.params = {
                c:'k'
            }
            console.log(config);
           return config; 
        })
        //2. ajax
        // 3. 响应拦截器
        axios.interceptors.response.use((res)=>{
           console.log(res); 
           // 加工数据格式
        //    res.abc = 123;
           return res.data;
        })
        btns[0].onclick =async function(){
            let res =await axios({
                url:"https://v1.hitokoto.cn"
            })
            console.log(res);
        }
        btns[1].onclick =async function(){
            let res =await axios({
                url:"http://localhost:3000/students"
            })
            console.log(res);
        }
    </script>
</body>

</html>